package com.lhkj.ct.meta.modules.gauge.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lhkj.ct.base.model.Option;
import com.lhkj.ct.base.model.dto.PageQuery;
import com.lhkj.ct.meta.modules.gauge.model.entity.TblScale;
import com.lhkj.ct.meta.modules.gauge.model.vo.ScalePageVo;
import com.lhkj.ct.meta.modules.psychology.model.bo.PsyExportParam;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author jobob
 * @since 2023-10-08
 */
public interface ScaleMapper extends BaseMapper<TblScale> {

    @Select("select t.id, scale_name, display_name, introduction, instruction, recommend, amount,scale_picture, t1.id as category,t2.id as usability, layout, chart, patient_module, status, sort, type, progress, question_json, t1.c_name, t2.u_name " +
            "from tbl_scale t " +
            "left join tbl_gauge_category t1 on t1.id = t.category " +
            "left join  tbl_gauge_usability t2 on t2.id = t.usability " +
            "where t.id = #{id} ")
    TblScale getForm(@Param("id") String id);

    IPage<ScalePageVo> selectScalePage(Page<TblScale> page, @Param("scale") TblScale tblScale, @Param("pageQuery") PageQuery pageQuery);

    @Select("<script>" +
            "select id as `value`, scale_name as `label` from tbl_scale where del_flag = '${@com.lhkj.ct.base.enums.DeleteStatus@NORMAL.code}' " +
            "<if test=\"pageQuery.keywords != null and pageQuery.keywords != ''\">" +
            "and scale_name like concat('%', #{pageQuery.keywords,jdbcType=VARCHAR}, '%')" +
            "</if> " +
            "order by sort " +
            "</script>")
    IPage<Option<String>> selectScaleOptions(Page<TblScale> page,@Param("pageQuery") PageQuery pageQuery);

    List<Map<String, List<Map<String, Object>>>> groupByCategory(@Param("scale") TblScale tblScale);

    Integer checkGaugeNameUnique(@Param("scale") TblScale scale);

    PsyExportParam getExportParamByScaleId(@Param("scaleId") String scaleId);
}
